package com.srv.persistence;

import com.srv.persistence.impl.DBIDPersistence;
import com.srv.persistence.impl.DBSummaryUserPersistence;
import com.srv.persistence.impl.DBTravelPersistence;
import com.srv.persistence.impl.DBNodePersistence;
import com.srv.persistence.impl.DBUserPersistence;
import com.srv.persistence.impl.DefaultResourcePersistence;
/**
 * 持久化工厂<br/>
 * 此工厂的设计主要避免将来利用不同的方法实现持久化.
 * @author Administrator
 *
 */
public class PersistenceFactory {
	
	private static ITravelPersistence theITravlePersistence = null; 
	private static INodePersistence theINodePersistence = null;
	private static IResourcePersistence theIResourcePersistence = null;
	private static IUserPersistence theIUserPersistence = null;
	private static ISummaryUserPersistence theSummaryUserPersistence = null;
	private static IIDPersistence theIDPersistence = null;
	/**
	 * 获取一个Travel持久化类
	 * @return ITravelPersistence的实例
	 */
	public static ITravelPersistence getTravelPersistence(){
		if(theITravlePersistence==null){theITravlePersistence=new DBTravelPersistence();}
		return theITravlePersistence;
	}
	/**
	 * 获取一个Node持久化类
	 * @return INodePersistence的实例
	 */
	public static INodePersistence getNodePersistence(){
		  if(theINodePersistence==null){theINodePersistence=new DBNodePersistence();}
		  return theINodePersistence;
	}
	/**
	 * 获取一个资源(图片、声音)持久化类
	 * @return IResourcePersistence的实例
	 */
	public static IResourcePersistence getResourcePersistence(){
		  if(theIResourcePersistence==null){theIResourcePersistence=new DefaultResourcePersistence();}
		  return theIResourcePersistence;
	}
	
	public static IUserPersistence getUserPersistence(){
		if(theIUserPersistence == null){
			theIUserPersistence = new DBUserPersistence();
		}
		return theIUserPersistence;
	}
	
	public static ISummaryUserPersistence getSummaryUserPersistence(){
		if(theSummaryUserPersistence == null){
			theSummaryUserPersistence = new DBSummaryUserPersistence();
		}
		return theSummaryUserPersistence;
	}
	public static IIDPersistence getIDPersistence(){
		if(theIDPersistence == null){
			theIDPersistence = new DBIDPersistence();
		}
		return theIDPersistence;
	}
}
